package com.zlq.easydbutils;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.zlq.easydbutils.factory.EasyFactory;

public class BankServiceImpl implements BankService {

	// 不使用事务的登录

	public List<Bank> qryBank2(String bank_no) {
		BankDao ud = EasyFactory.newDaoInstance(BankDao.class);
		List<Bank> banks = null;
		try {
			banks = ud.getBankByBank2(bank_no);
			/*
			 * int iii = banks.size(); for (int i = 0; i < iii; i++) { Bank aa =
			 * banks.get(i); System.out.println(aa.getBank_no() + "`" +
			 * aa.getBishu()); }
			 */

			// System.out.println(ii.toString());
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return banks;
	}
	public List<Map<String, Object>> qryBankMap(String bank_no) {
		BankDao ud = EasyFactory.newDaoInstance(BankDao.class);
		List<Map<String, Object>> banks = null;
		try {
			banks = ud.getBankByBankMap(bank_no);

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return banks;
	}
	
	public List<Object> qryBankArray(String bank_no) {
		BankDao ud = EasyFactory.newDaoInstance(BankDao.class);
		List banks = null;
		try {
			banks = ud.getBankByBank2(bank_no);

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return banks;
	}
	// 使用事务

	public void addBank2(List<Bank> bank) {

		BankDao ud = EasyFactory.newDaoInstance(BankDao.class);
		try {
			int iii = bank.size();
			for (int i = 0; i < iii; i++) {
				Bank aa = bank.get(i);
				ud.addBank(aa);
			}
			// 没使用事务让其产生除0异常
			// 在接口上声明注解让其产生除0异常
			// @SuppressWarnings("unused")
			// /int a = 1/0;
			// ud.addUser(user);
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	@Override
	public void addBank(Bank bank) {
		// TODO Auto-generated method stub
		BankDao ud = EasyFactory.newDaoInstance(BankDao.class);
		try {

			ud.addBank(bank);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void updBank(Bank bank) {
		// TODO Auto-generated method stub
		BankDao ud = EasyFactory.newDaoInstance(BankDao.class);
		try {

			ud.updBank(bank);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
